package it.hansir.sonic_tbs;

import android.os.Bundle;
import android.webkit.WebView;

import com.tencent.sonic.sdk.SonicSessionClient;

import java.util.HashMap;

/**
 * 创建者 by ${HanSir} on 2017/9/28.
 * 版权所有  WELLTRANS.
 * 说明      SonicSessionClient主要负责跟webView的通信，比如调用webView的loadUrl、loadDataWithBaseUrl等方法
 */

public class SonicSessionClientImp extends SonicSessionClient {
    private WebView webView;

    public SonicSessionClientImp(WebView webView) {
        LogUtil.d(this,"SonicSessionClientImp构造");
        this.webView = webView;
    }

    public WebView getWebView() {
        LogUtil.d(this,"SonicSessionClientImp构造getWebView");
        return webView;
    }

    @Override
    public void loadUrl(String url, Bundle extraData) {
        LogUtil.d(this,"loadUrl");
            webView.loadUrl(url);
    }

    @Override
    public void loadDataWithBaseUrl(String baseUrl, String data, String mimeType, String encoding, String historyUrl) {
            webView.loadDataWithBaseURL(baseUrl,data,mimeType,encoding,historyUrl);
        LogUtil.d(this,"loadDataWithBaseUrl");
    }

    @Override
    public void loadDataWithBaseUrlAndHeader(String baseUrl, String data, String mimeType, String encoding, String historyUrl, HashMap<String, String> headers) {
            webView.loadDataWithBaseURL(baseUrl,data,mimeType,encoding,historyUrl);
        LogUtil.d(this,"loadDataWithBaseUrlAndHeader");
    }

    public void destroy() {
        if (null != webView) {
            webView.destroy();
            webView = null;
        }
    }
}
